package redis.gambing;

import org.apache.storm.redis.common.mapper.RedisDataTypeDescription;
import org.apache.storm.redis.common.mapper.RedisStoreMapper;
import org.apache.storm.tuple.ITuple;

import static redis.gambing.GambleFinalString.GAMBLER_ID;
import static redis.gambing.GambleFinalString.HASH_GAMBLER_2_TIMES;

public class GamblerTimesInfoStoreMapper implements RedisStoreMapper {
    private final RedisDataTypeDescription description;

    public GamblerTimesInfoStoreMapper() {
        description = new RedisDataTypeDescription(RedisDataTypeDescription.RedisDataType.HASH, HASH_GAMBLER_2_TIMES);
    }

    @Override
    public RedisDataTypeDescription getDataTypeDescription() {
        return description;
    }

    @Override
    public String getKeyFromTuple(ITuple tuple) {
        return tuple.getStringByField(GAMBLER_ID);
    }

    @Override
    public String getValueFromTuple(ITuple tuple) {
        return Short.toString(tuple.getShortByField(HASH_GAMBLER_2_TIMES));
    }
}
